﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 班组成员
    /// </summary>
    public partial class TeamMember : BusEntity
    {
        /// <summary>
        /// 班组编号
        /// </summary>
        public string TeamId { set; get; }
        /// <summary>
        /// 工位ID
        /// </summary>
        public string StationId { set; get; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserId { set; get; }
        /// <summary>
        /// 成员编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 成员名称
        /// </summary>
        public string Name { get; set; }
    }

    public partial class TeamMember : BusEntity
    {
        public Team Team { set; get; }
        /// <summary>
        /// 用户实体
        /// </summary>
        public Sys_User User { set; get; }

        /// <summary>
        /// 工位实体
        /// </summary>
        public WorkshoStation Station { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class TeamMemberTypeConfig : BusEntityTypeConfig<TeamMember>, IEntityTypeConfiguration<TeamMember>
    {
        public override void Configure(EntityTypeBuilder<TeamMember> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Team).WithMany(p=>p.Members).HasForeignKey(p => p.TeamId);
            builder.HasOne(p => p.User).WithMany().HasForeignKey(p => p.UserId);
            builder.HasOne(p => p.Station).WithMany().HasForeignKey(p => p.StationId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.TeamId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.StationId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.UserId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("班组成员");
            builder.Property(p => p.TeamId).HasComment("班组ID");
            builder.Property(p => p.StationId).HasComment("负责工位ID");
            builder.Property(p => p.UserId).HasComment("用户ID");
            builder.Property(p => p.Code).HasComment("成员编码");
            builder.Property(p => p.Name).HasComment("成员名称");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
